<?PHP
#
# author: Cody Sorgenfrey
# (c)2012 South Hill Calvary Chapel
#

include_once("../mysql/database_info.php");
include_once("common.php");
include_once("../mysql/common.php");

if (!isset($_GET['id'])) {
  die ("Error:  Must define id.");
}
$id = $_GET['id'];

if ($id < 1) {
  die ("Error:  id: $id must be greater than 0");
}

$table = "events";
connect_select_test($table);
$query="SELECT * FROM $table WHERE id='$id'";
$result=mysql_query($query) or die (mysql_error());
$num_rows=mysql_num_rows($result);

if ($num_rows !=1) {
  die ("The number events with this id should be equal to 1");
}

$date=mysql_result($result,$i,"start");
$php_start_time = strtotime($date);
$date=mysql_result($result,$i,"end");
$php_end_time = strtotime($date);

$date=mysql_result($result,$i,"start");
$no_start=mysql_result($result,$i,"no_start");
$php_start_time = strtotime($date);

$date=mysql_result($result,$i,"end");
$no_end=mysql_result($result,$i,"no_end");
$php_end_time = strtotime($date);

$php_end_day = date("z", $php_end_time);
$php_start_day = date("z",$php_start_time);


if ($no_start) {
	$duration = 0;
} else if ($no_end) {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$duration = $date1;
} else if ($php_end_day != $php_start_day) {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$date2 = date("l, F jS", $php_end_time);
	$duration = $date1 . " - " . $date2;
} else {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$date2 = date("g:i a", $php_end_time);
	$duration = $date1 . " - " . $date2;
}
$duration = strtoupper($duration);


$title=strtoupper(mysql_result($result,$i,"title"));
$announcement=mysql_result($result,$i,"announcement");
$ministry=mysql_result($result,$i,"ministry");
$teaser=mysql_result($result,$i,"teaser");
$picture="http://www.southhillcalvary.org/".mysql_result($result,$i,"picture");
$flyer=mysql_result($result,$i,"flyer");
$directions=mysql_result($result,$i,"directions");
$registration=mysql_result($result,$i,"registration");
$localRegistrationFile=mysql_result($result, $i, "localRegistrationPage");
$payment=mysql_result($result,$i,"payment");
$costPerPerson = mysql_result($result, $i, "costPerPerson");
$costPerCouple = mysql_result($result, $i, "costPerCouple");
$maxCost = mysql_result($result, $i, "maxCost");


$meta_key=htmlspecialchars($title.' feature, event, happenings, calendar, special, function, special', ENT_QUOTES);
$meta_desc=htmlspecialchars('This week South Hill Calvary Chapel is featuring the following special event: '.$title.'.',ENT_QUOTES);
$title = htmlspecialchars($title, ENT_QUOTES);
$morehtml= null;
$morejava= null;

startPage($title, $meta_key, $meta_desc, $morehtml, $morejava);

if (!$no_start) {
	$title = $title." -- ".$duration;
}

mpicture_caption($picture, "98%", 0, $teaser, "1%");
printf("\t\t\t<div class='paragraph'>\n");
printf("\t\t\t\t<p style='font-family: Gnuolane;'>%s</p>\n",$announcement);
printf("\t\t\t</div>\n");

if (!empty($flyer)) {
	printf("\t\t\t<div  class='paragraph'>\n");
	printf("\t\t\t\t<b><a href='http://www.southhillcalvary.org%s' target='_blank'><h5>Click here for additional details in the FLYER</h5></a>\n",$flyer);
	printf("\t\t\t</div>\n");
}
if (!empty($directions)) {
	printf("\t\t\t<div  class='paragraph'>\n");
	printf("\t\t\t\t<a href='%s' target='_blank'><h5>Click here for DIRECTIONS</h5></a>\n",$directions);
	printf("\t\t\t</div>\n");
}
if (!empty($registration)) {
	printf("\t\t\t<div class='paragraph'>\n");
	printf("\t\t\t\t<a href='%s' target='_blank'><h5>GET REGISTERED!</h5></a>\n",$registration);
	printf("\t\t\t</div>\n");
}

if (!empty($payment)) {
	printf("\t\t\t<div class='paragraph'>\n");
	printf("\t\t\t\t<a href='%s' target='_blank'><h5>PURCHASE TICKETS OR MAKE PAYMENT</h5></a>\n",$payment);
	printf("\t\t\t</div>\n");
}
endPage();
?>
